package com.plugin.manage.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * 数据源配置类
 * 当前使用单数据源，为将来双数据源扩展预留接口
 * 
 * @author mark
 * @date 2025-07-23
 */
@Configuration
public class DataSourceConfig {

    /**
     * 主数据源配置
     * 当前使用的数据源，标记为@Primary
     */
    @Bean
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.druid.primary")
    public DataSource primaryDataSource() {
        return new DruidDataSource();
    }

    /* 
     * 将来双数据源扩展示例代码（暂时注释）：
     * 
     * @Bean
     * @ConfigurationProperties(prefix = "spring.datasource.dynamic.datasource.master")
     * public DataSource masterDataSource() {
     *     return new DruidDataSource();
     * }
     * 
     * @Bean
     * @ConfigurationProperties(prefix = "spring.datasource.dynamic.datasource.slave")
     * public DataSource slaveDataSource() {
     *     return new DruidDataSource();
     * }
     * 
     * @Bean
     * @Primary
     * public DataSource dynamicDataSource() {
     *     DynamicDataSource dynamicDataSource = new DynamicDataSource();
     *     Map<Object, Object> dataSourceMap = new HashMap<>();
     *     dataSourceMap.put("master", masterDataSource());
     *     dataSourceMap.put("slave", slaveDataSource());
     *     dynamicDataSource.setTargetDataSources(dataSourceMap);
     *     dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
     *     return dynamicDataSource;
     * }
     */
}
